//
//  VideoReusableView.m
//  Project_B
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 ZY. All rights reserved.
//

#import "VideoReusableView.h"

@interface VideoReusableView ()

@property (nonatomic, strong)UIImageView *headerImageView;
@property (nonatomic, strong)UILabel *headerLabel;

@end

@implementation VideoReusableView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}



- (void)createSubViews
{
    
}


#pragma mark - 重写set方法
- (void)setVideoHeaderModel:(VideoHeaderModel *)videoHeaderModel
{
    _videoHeaderModel = videoHeaderModel;
    
    // 赋值
    self.headerLabel.text = self.videoHeaderModel.title;
    // 图片
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:self.videoHeaderModel.imgsrc] placeholderImage:PLACEHOLDER_IMAGE];
    
}




#pragma mark - 重写headerArray set方法（循环赋值）
- (void)setHeaderArray:(NSMutableArray *)headerArray
{
    _headerArray = headerArray;
    
    
    for (int i = 0; i < self.headerArray.count; i++) {
        
#pragma mark - 头视图imageView
        self.headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15 + i * (((SCREEN_WIDTH - 15 * 2 - 30 * 3) / 4) + 30), 15, (SCREEN_WIDTH - 15 * 2 - 30 * 3) / 4, (SCREEN_WIDTH - 15 * 2 - 30 * 3) / 4)];
        // tag值
        self.headerImageView.tag = 100 + i;
        // 变圆
        self.headerImageView.layer.cornerRadius = ((SCREEN_WIDTH - 15 * 2 - 30 * 3) / 4) / 2;
        self.headerImageView.userInteractionEnabled = YES;
        // 添加轻拍
        UITapGestureRecognizer *headerImageViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [self.headerImageView addGestureRecognizer:headerImageViewTap];
        [self addSubview:self.headerImageView];
        // 赋值
        [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:((VideoHeaderModel *)self.headerArray[i]).imgsrc] placeholderImage:PLACEHOLDER_IMAGE];
        
        
        
#pragma mark - 头视图文字label
        self.headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15 + i * (((SCREEN_WIDTH - 15 * 2 - 30 * 3) / 4) + 30), 85, (SCREEN_WIDTH - 15 * 2 - 30 * 3) / 4, 20)];
        self.headerLabel.font = [UIFont systemFontOfSize:14.0];
        self.headerLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.headerLabel];
        // 赋值
        self.headerLabel.text = ((VideoHeaderModel *)self.headerArray[i]).title;
        
    }
    
}




#pragma mark - 头视图imageView点击方法
- (void)tapAction:(UITapGestureRecognizer *)sender
{
#pragma mark - 3.delegate：执行协议方法（相当于谁来调用这个方法）
    [self.tapDelegate presentViewToViewController:sender.view.tag];
}




@end
